<!doctype html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security" xmlns:auth=""
>
<auth:data uri="/upload/image,/personal/avatar.json"/>
<head>
    <th:block th:include="common/head::noXadmin('个人信息')"/>
</head>
<body class="layui-layout layui-layout-admin layui-bg-gray">
<div class="layui-container ">
    <div class="layui-row layui-col-space10">
        <div class="layui-col-xs4">
            <div class="layui-card">
                <div class="layui-card-header">个人资料</div>
                <div class="layui-card-body " style="text-align: center;">
                    <img th:src="${user.avatar}" id="avatarUrl" class="layui-circle"
                         style="width: 120px;height: 120px;"><br/>
                    <a id="selectImg">修改头像</a>
                    <table class="layui-table" lay-skin="line" lay-size="sm">
                        <tbody>
                        <tr>
                            <td class="text-align-left">姓名：</td>
                            <td class="text-align-right" th:text="${user.name}"></td>
                        </tr>
                        <tr>
                            <td class="text-align-left">性别：</td>
                            <td class="text-align-right" th:text="${user.sex}">性别</td>
                        </tr>
                        <tr>
                            <td class="text-align-left">手机号：</td>
                            <td class="text-align-right" th:text="${user.mobile}">手机号</td>
                        </tr>
                        <tr>
                            <td class="text-align-left">账号类型：</td>
                            <td class="text-align-right" th:text="${user.roles}">${user.roles}</td>
                        </tr>
                        <tr>
                            <td class="text-align-left">所属部门：</td>
                            <td class="text-align-right" th:text="${deptName}">所属部门</td>
                        </tr>

                        <tr>
                            <td class="text-align-left">邮箱地址：</td>
                            <td class="text-align-right" th:text="${user.email}">邮箱地址</td>
                        </tr>
                        <tr>
                            <td class="text-align-left">创建时间：</td>
                            <td class="text-align-right" th:text="${#dates.format(user.ctime,'YYYY-MM-dd')}">创建时间</td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <div class="layui-col-xs8">
            <div class="layui-card">
                <div class="layui-card-header">基础信息</div>
                <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                    <ul class="layui-tab-title">
                        <li class="layui-this">基本资料</li>
                        <li>安全设置</li>
                    </ul>
                    <div class="layui-tab-content" style="height: 100px;">
                        <div class="layui-tab-item layui-show">
                        </div>
                        <div class="layui-tab-item">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

</div>
<script>
    layui.use('croppers', function () {
        var $ = layui.jquery
            , croppers = layui.croppers;

        function updateAvatar(url) {
            $("#avatarUrl").attr('src', url);
            $.ajax({
                url: "/personal/avatar.json",
                type: "PUT",
                dataType: 'json',
                data: {avatar: url},
                success: function (req) {
                    console.log(req);
                }

            })
        }

        croppers.render({
            elem: '#selectImg'
            , saveW: 350     //保存宽度
            , saveH: 350
            , data: {busType: "avatar"}
            , mark: 1 / 1    //选取比例
            , area: '900px'  //弹窗宽度
            , url: "/upload/image"  //图片上传接口返回和（layui 的upload 模块）返回的JOSN一样
            , done: function (url) { //上传完毕回调
                updateAvatar(url);

            }
        });
    });
</script>

</body>

</html>
